<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">联系人</span>
        <input type="text" class="summer-input" id="storeOwner"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="10%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="10%">
	    <col width="20%">
	    <thead>
		    <tr>
		    	<th><input type="checkbox" id="checkAll" name="checkAll" >全选</th>
		    	<th>序号</th>
		        <th>店铺名称</th>
		        <th>店铺地址</th>
		        <th>邮箱</th>
		        <th>联系人</th>
		        <th>手机号</th>
		        <th>状态</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
	   	AGREE: basePath + "${common_url}agree",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	DEL: basePath + "${common_url}del"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:agree']
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#storeOwner').val('');
        	reloadTable();
        });
       //全选
       $("#checkAll").on('click',function(){
    	   $("[name='id']").attr("checked",'true');//全选
       });
       createTable();
       //审核通过
       $('#toolbar').on('click', 'a[data-permit="${name_english}:agree"]', function() {
    	   var id = $("input[name='id']:checked").serialize();
           $.ajax({
			   url: CONST_URL.AGREE + '?id=' + id,//请求的后台地址
			   success: function(data){
				   reloadTable();
			   }
			});
       });	
     
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEdit"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '?id=' + id;
        });	
        
        //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:del"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
    });
    
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"storeOwner": trimSpace($('#storeOwner').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"storeOwner": trimSpace($('#storeOwner').val())
            	}
    		},
    		columns: [
    		     {
    		    	 field : 'id', 
    		    	 render : function(rowData){
							return '<input type="checkbox" id="id" name="id" value="'+rowData.id+'">';
						}
    		     },
    		     {
    		    	field: 'reorder' 
    		     },
    		     {
    		    	 field: 'storeName'/* ,
    		    	 render: function (rowData) {
    		    		 $('#storeName').combobox({
    		                 url : CONST_URL.GET_NAME_LIST, 
    		                 valueField : 'id',
    		                 async:false,
    		                 textField : 'name'
    		             }); 
    		    	 } */
    		     },
    		     {
    		    	 field: 'storeAddr'
    		     },
    		     {
    		    	 field:'email'
    		     },
    		     {
    		    	 field:'storeOwner'
    		     },
    		     {
    		    	 field:'phone'
    		     },
    		     {
    		    	 field:'state'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 2,    //显示数量
    		    			 permit: ['${name_english}:initEdit', '${name_english}:del'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    		          
    	    ]
    	});
    }

   
   
</script>
</body>
</html>